package com.wbt.jdk.serializable;

import com.wbt.entity.Test;
import com.wbt.entity.User;

import java.io.*;

/**
 * @program: Thread-demo
 * @description:
 * @author: Wang·Baotong
 * @create: 2021-05-08 15:30
 */
public class Main {

    public static void main(String[] args) throws Exception{

        out();
        input();
    }

    public static void out() throws Exception {
        Test t = new Test();
        t.setName("张三");
        t.setAge(31);
        t.setData("复旦附属凤飞飞！");

        User u = new User();
        u.setName("朴树");
        u.setTell(1567777777);

        t.setUser(u);

        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File("E:/Test.txt")));
        oo.writeObject(t);
        System.out.println("out完成");
        oo.close();
    }

    public static void input() throws Exception {
        ObjectInputStream oi = new ObjectInputStream(new FileInputStream(new File("E:/Test.txt")));
        Test it = (Test) oi.readObject();
        System.out.println("input完成");
        System.out.println(it.toString());
    }

}
